class GitDataCommits
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def getCommit(repo, sha, user=nil)
    username = user == nil ? @github.username : user
    @github.get(
        'repos/%s/%s/git/commits/%s' % [username, repo, sha])
  end

  def createCommit(repo, message, tree, parents, authorName=nil,
      authorEmail=nil, authorDate=nil, committerName=nil,
      committerEmail=nil, commiterDate=nil, user=nil)
    username = user == nil ? @github.username : user
    author = {
        :name => authorName,
        :email => authorEmail,
        :date => authorDate,
    }
    author = @github.removeEmptyParams(author)
    committer = {
        :name => committerName,
        :email => committerEmail,
        :date => commiterDate
    }
    committer = @github.removeEmptyParams(committer)
    params = {
        :message => message,
        :author => author,
        :committer => committer,
        :parents => parents,
        :tree => tree
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.post(
        'repos/%s/%s/git/commits' % [username, repo], data)
  end
end